package com.yzd.learnjava.io;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.RandomAccess;

import javax.naming.ldap.Rdn;

import com.yzd.learnjava.util.Print;

public class UsingRandomAccessFile {
	static String file = "rtest.dat";
	public static void dispaly() throws IOException {
		RandomAccessFile rf = new RandomAccessFile(file, "r");
		for(int i = 0 ; i < 7; i++) {
			Print.print("Value " + i + ": " + rf.readDouble());
		}
		Print.print(rf.readUTF());
		rf.close();
	}
	public static void main(String[] args) throws IOException {
		RandomAccessFile rf = new RandomAccessFile(file, "rw");
		for(int i = 0 ; i < 7; i++) {
			rf.writeDouble(i * 1.414);
		}
		rf.writeUTF("The end of the file");
		rf.close();
		dispaly();
		rf = new RandomAccessFile(file, "rw");
		rf.seek(5 * 8);
		rf.writeDouble(47.0001);
		rf.close();
		dispaly();
	}
}
